package com.app.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.app.mapper.PrizeMapper;
import com.app.model.Prize;
import com.app.service.IPrizeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 奖品 服务实现类
 * </p>
 *
 * @author yoominic
 * @since 2023-12-16
 */
@Service
public class PrizeServiceImpl extends ServiceImpl<PrizeMapper, Prize> implements IPrizeService {

    @Override
    public Object prizeList(Integer gameId) {
        QueryWrapper<Prize> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("game_id", gameId);
        Prize prize = super.baseMapper.selectOne(queryWrapper);
        if (prize != null && prize.getPrize() != null) {
            List<Prize> prizeList = JSON.parseObject(prize.getPrize(), new TypeReference<List<Prize>>() {
            });
            for (Prize prize1 : prizeList) {
                if (prize1.getPrizeType() == 1) {
                    prize1.setPrizeTypeText("优惠券");
                }
                if (prize1.getPrizeType() == 2) {
                    prize1.setPrizeTypeText("实物");
                }
                if (prize1.getPrizeType() == 3) {
                    prize1.setPrizeTypeText("积分");
                }
                if (prize1.getPrizeType() == 4) {
                    prize1.setPrizeTypeText("谢谢参与");
                }
            }
            return prizeList;
        } else {
            return new ArrayList<>();
        }
    }
}
